<?php
class User extends AppModel{

	//var $useTable = false;
	
	var $validate = array(
		
		'first_name' => array(
			'rule' => 'notEmpty',
			'message' => 'Bitte geben Sie einen Vornamen an'
			),
		'family_name' => array(
			'rule' => 'notEmpty',
			'message' => 'Bitte geben Sie einen Nachnamen an'
			),
		'username' => array(
			'rule' => 'notEmpty',
			'message' => 'Bitte geben Sie einen Usernamen an'
			),
		'password' => array(  	
			'rule' => array('minLength', '8'),
			'message' => 'Mimimum 8 Zeichen lang' 
			)

		);

	var $belongsTo = 'State';

	var $hasAndBelongsToMany = array( 
		'Role' => array(
			'className' => 'Role',
			'joinTable' => 'user_has_roles',
			'foreignKey' => 'user_id',
			'associationForeignKey' => 'role_id',
			'unique' => true,
			'conditions' => array('UserHasRole.state_id'=>1),
			'fields' => '',
			'order' => '', 
			'limit'  => '', 
			'offset'  => '', 
			'finderQuery' => '',
			'deleteQuery' => '', 
			'insertQuery'  => ''  
		)
	);
	
	function isAdmin($userData){
		$isAdmin = preg_match(REGEX_ADMIN_OR_OPERATOR,$userData['Role']['role_name'],$matches)>0;
		return true;
	}
	
	function isOperator(){
		return true;
	}


}
?>
